<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script th:src="@{/static/js/vue3.4.21.js}"></script>
    <script th:src="@{/static/js/axios.min.js}"></script>
</head>
<body>
<h1>使用Vue3+axios+thymeleaf+springmvc发送AJAX请求</h1>
<hr/>
<div id="app">
    <h1>{{message}}</h1>
    <button @click="getMessage">获取消息</button>
    <button @click="getUser">获取用户信息</button>
</div>
<hr/>
<form th:action="@{/save}" method="post">
    用户名：<input type="text" name="username"><br>
    密码：<input type="text" name="password"><br>
    <input type="submit" value="保存">
</form>
<hr/>
<form th:action="@{/save2}" method="post">
    用户名：<input type="text" name="username"><br>
    密码：<input type="text" name="password"><br>
    <input type="submit" value="保存">
</form>

<script th:inline="javascript">
    Vue.createApp({
        data() {
            return {
                message: "这里的信息将被刷新"
            }
        },
        methods: {
            // async getMessage(){
            //     try {
            //         const response = await axios.get([[@{/}]] + 'hello')
            //             this.message = response.data
            //     }catch (e) {
            //             console.error(e)
            //         }
            //     }
            // },
            async getUser() {
                try {
                    const response = await axios.get([[@{/}]] + 'getUser')
                        this.message = response.data
                }catch
                    (e)
                    {
                        console.error(e)
                    }
                }
            }
        }).mount("#app")
</script>
</body>
</html>